package com.quwan.manager.controller;

import com.quwan.common.BaseController;
import com.quwan.common.result.ApiResult;
import com.quwan.common.result.PageResult;
import com.quwan.manager.controller.dto.CircleCommentDto;
import com.quwan.manager.service.ICircleCommentService;
import com.quwan.utils.Parse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author laozhang
 * @date 2022/3/17
 */
@Api(tags = "后台圈子评论管理接口")
@RestController
@RequiredArgsConstructor
@RequestMapping("mgr/circleComment")
public class CircleCommentController extends BaseController {

    private final ICircleCommentService circleCommentService;


    @ApiOperation(value = "圈子评论列表分页",notes = "<span style=\"color:red\">注意参数是否必填</span>",httpMethod = "POST")
    @PostMapping("circleCommentListPage")
    public ApiResult<PageResult<CircleCommentDto>> circleCommentListPage(@RequestParam(defaultValue = "1") int page,
                                                           @RequestParam(defaultValue = "10") int size,
                                                           @ApiParam(value="圈子id",required = false) @RequestParam(required = false) String circleId,
                                                           @ApiParam(value="开始时间（yyyy-MM-hh）",required = false) @RequestParam(required = false) String beginTime,
                                                           @ApiParam(value="结束时间（yyyy-MM-hh）",required = false) @RequestParam(required = false) String endTime) {
        PageResult<CircleCommentDto> res = circleCommentService.getCircleCommentListPage(page, size,Parse.toLong(circleId) , beginTime, endTime);
        return ApiResult.success(res);
    }

    @ApiOperation(value = "圈子评论列表",notes = "<span style=\"color:red\">注意参数是否必填</span>",httpMethod = "POST")
    @PostMapping("circleCommentList")
    public ApiResult<List<CircleCommentDto>> circleCommentList(@ApiParam(value="圈子id",required = true) @RequestParam(required = true) String circleId,
                                                            @ApiParam(value="开始时间（yyyy-MM-hh）",required = false) @RequestParam(required = false) String beginTime,
                                                            @ApiParam(value="结束时间（yyyy-MM-hh）",required = false) @RequestParam(required = false) String endTime) {
        List<CircleCommentDto> res = circleCommentService.getCircleCommentList(Parse.toLong(circleId),beginTime, endTime);
        return ApiResult.success(res);
    }

    @PostMapping("delCircleComment")
    @ApiOperation("删除圈子评论")
    public ApiResult delCircleComment(@RequestParam(value = "id") String id){
        boolean success = circleCommentService.delCircleComment(Long.valueOf(id));
        if (success)
            return ApiResult.successMsg();
        else
            return ApiResult.failed();
    }
   

}
